package misty.mispic.app.base

import javafx.fxml.FXMLLoader
import javafx.scene.Node
import javafx.scene.control.Skin
import javafx.scene.control.Skinnable
import misty.mispic.app.ui.FXML

/**
 * Created by Misty on 2015/1/15.
 */
abstract class SkinBase implements Skin {
    protected Skinnable skinnable
    protected Node node

    SkinBase(Skinnable skinnable) {
        this.skinnable = skinnable
    }

    @Override
    Skinnable getSkinnable() {
        return this.skinnable
    }

    Node getNode(FXML fxml) {
        return getNode(fxml.location)
    }

    Node getNode(URL location) {
        if (!this.@node) {
            this.node = new FXMLLoader(location).with {
                controller = skinnable
                load()
            }
        }
        return this.@node
    }

    @Override
    void dispose() {

    }
}
